package ui;

import dao.DaoLogic;
import javabean.Admin;
import org.apache.ibatis.session.SqlSession;
import service.ServiceLogic;
import service.imp.ServiceLogicImp;
import tools.Dbutils;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Scanner;

import static ui.Show.view;
//表现层
public class admin {
    public static void main(String[] args) {
        ServiceLogicImp serviceLogicImp = new ServiceLogicImp();
        while (true) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("--------------请登录--------------");
            System.out.println("账户：");//aaa
            String user = scanner.next();
            System.out.println("密码：");//123456
            String password = scanner.next();
            String captcha = Dbutils.captcha();
            System.out.println(captcha);
            System.out.println("验证码：");
            String next = scanner.next();
            Admin admin = serviceLogicImp.adminService(user, password);
            if(!captcha.equals(next)){
                System.out.println("验证码错误");
                continue;
            }
            if(admin==null){
                System.out.println("用户名或密码错误，请重试");
                continue;
            }else{
                view();
                break;
            }
        }
//        while (true) {
//            Scanner scanner = new Scanner(System.in);
//            System.out.println("--------------请登录--------------");
//            System.out.println("账户：");//aaa
//            String user = scanner.next();
//            System.out.println("密码：");//123456
//            String password = scanner.next();
//            String captcha = Dbutils.captcha();
//            System.out.println(captcha);
//            System.out.println("验证码：");
//            String next = scanner.next();
//            Dbutils.log();
//            SqlSession sqlSession = Dbutils.getsqlSession();
//            DaoLogic mapper = sqlSession.getMapper(DaoLogic.class);
//            Admin admin1 = new Admin();
//            admin1.setUser(user);
//            admin1.setPassword(password);
//            Admin admin = mapper.isAdmin(admin1);
////            Admin admin = Dbutils.queryBean("select * from admin where user=? and password=?",
////                    Admin.class, user, password);
//            if(!captcha.equals(next)){
//                System.out.println("验证码错误");
//                continue;
//            }
//            if(admin==null){
//                System.out.println("用户名或密码错误，请重试");
//                continue;
//            }else{
//                view();
//                break;
//            }
//        }
    }
}

